package com.ywdj.framework.service;

import com.ywdj.framework.dao.UserDao;
import com.ywdj.framework.entity.sys.UserEntity;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author darkevil
 */
@Service
@Slf4j
public class UserService implements UserDetailsService {
    @Autowired
    private UserDao userDao;

    public List<UserEntity> listUsers() {
        val list = new ArrayList<UserEntity>();
        return list;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        val queryUserEntity = new UserEntity();
        queryUserEntity.setLoginName(username);
        val user = userDao.selectUser(queryUserEntity);
        if (user == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }
        return user;
    }
}
